//index.js
//获取应用实例
var a = getApp();

Page({
    data: {
        pdata:{},
        name:"",
        number:"",
        bname:"",
        bnumber:"",
        bankValue:"",
        kbank:"",
        bankValue:'',
        list:[],
        bfList:[],
        bank:[],
        isytpj: !1,
        pagenum: 1,
        mygd: !1,
        jzgd: !0,
        params:{},
        userInfo:{},
        yajin:0,
        total_day:0
    },
    onLoad: function(e) {
      var type = e.type;
     
      this.setData({
        userInfo:a.globalData.userInfo,
        'type':type,
        bank: getApp().xtxx1.set.bank,
        money: getApp().xtxx1.set.money,
      });
      this.getList(type);
      this.getjibuInfo();
    },
    getjibuInfo: function () {
      var s = this;
      a.util.request({
        url: "entry/wxapp/jibuInfo",
        cachetime: "0",
        success: function (t) {
          console.log(t.total_day)
          s.setData({
            yajin: t.data.yajin.yajin_money,
            total_day: t.data.total_day
          })
          if (t.data.userInfo){
            s.setData({
              userInfo: t.data.userInfo
            })
          }
        }
        });
    },
    getList: function () {
      var s = this, o = s.data.pagenum;
 
      s.data.params.page = o, s.data.params.type = s.data.type, s.data.params.pagesize = 10, console.log(o, s.data.params),
        s.setData({
          isjzz: !0
        }), a.util.request({
          url: "entry/wxapp/record",
          cachetime: "0",
          data: s.data.params,
          success: function (t) {
            console.log("分页返回列表数据", t.data);
            var a = [{
              name: "全部",
              num: t.data.all
            }, {
              name: "满意",
              num: t.data.ok
            }, {
              name: "不满意",
              num: t.data.no
            }], e = s.data.bfList;
            e = function (t) {
              for (var a = [], e = 0; e < t.length; e++) -1 == a.indexOf(t[e]) && a.push(t[e]);
              return a;
            }(e = e.concat(t.data)), s.setData({
              list: e,
              bfList: e,
              navbar: a
            }), t.data.length < 10 ? s.setData({
              mygd: !0,
              jzgd: !0,
              isjzz: !1
            }) : s.setData({
              jzgd: !0,
              pagenum: o + 1,
              isjzz: !1
            }), console.log(e);
          }
        });
    },
    TakeCash: function() {
        this.setData({
            TakeCash: true,
            TakeCash_box: true
        })
    },
    CloseTakeCash: function() {
        this.setData({
            TakeCash: false,
            TakeCash_box: false,
            zfb_is_show: false,
            bank_is_show: false,
        })
    },
    nameInput: function (e) {
      this.setData({
        name: e.detail.value
      })
    },
    numberInput: function (e) {
      this.setData({
        number: e.detail.value
      })
    },
    bnameInput: function (e) {
      this.setData({
        bname: e.detail.value
      })
    },
    bnumberInput: function (e) {
      this.setData({
        bnumber: e.detail.value
      })
    },
    bankValueInput: function (e) {
      this.setData({
        bankValue: e.detail.value
      })
    },
    kbankInput: function (e) {
      this.setData({
        kbank: e.detail.value
      })
    },
    nameInput: function (e) {
      this.setData({
        name: e.detail.value
      })
    },
    zfb__show__box: function() {
        this.setData({
            zfb_is_show: true,
            pay_type:'alipay',
            TakeCash_box: false,
        })
    },
    bank__show__box: function() {
        this.setData({
            bank_is_show: true,
            pay_type: 'bankpay',
            TakeCash_box: false,
        })
    },
    // 选择时间
    ShowPricker: function() {
        this.setData({
            isShowPricker: true,
        })
    },
    bandAlipay: function(e){
      var pdata = this.data.pdata;
      if (this.data.pay_type == 'alipay'){
        if (this.data.name == '') {
          wx.showToast({
            title: '支付宝姓名',
            icon: 'none',
            duration: 500
          })
          return false;
        }
        if (this.data.number == '') {
          wx.showToast({
            title: '支付宝账号',
            icon: 'none',
            duration: 500
          })
          return false;
        }
        pdata.name = this.data.name;
        pdata.zhanghao = this.data.number;
        
      }else{
        if (this.data.bname == '') {
          wx.showToast({
            title: '请输入姓名',
            icon: 'none',
            duration: 500
          });
          return false;
        }
        if (this.data.bnumber == '') {
          wx.showToast({
            title: '请输入银行卡号',
            icon: 'none',
            duration: 500
          });
          return false;
        }
        if (this.data.bankValue == '') {
          wx.showToast({
            title: '请选择银行',
            icon: 'none',
            duration: 500
          });
          return false;
        }
        if (this.data.kbank == '') {
          wx.showToast({
            title: '请输入开户行宝账号',
            icon: 'none',
            duration: 500
          });
          return false;
        }
        pdata.name = this.data.bname;
        pdata.zhanghao = this.data.bnumber;
        pdata.bank = this.data.bankValue;
        pdata.kbank = this.data.kbank;
      }
      pdata.pay_type = this.data.pay_type;
      
      a.util.request({
        url: "entry/wxapp/tixian",
        cachetime: "0",
        data: pdata,
        success: function (e) {
          if (console.log(e), "1" == e.data.status) {
            a.onShow(), wx.showToast({
              title: e.data.msg,
              icon: "success",
              duration: 1e3
            });
            setTimeout(function () {
              wx.navigateTo({
                url: '../withdraw/index?type=tixian'
              })
            }, 1e3);
          }
         else {
            wx.showToast({
              title: e.data.msg,
              icon: "none",
              duration: 1e3
            });
          }
        },
        fail: function (e) {
          wx.showToast({
            title: '网络错误',
            icon: "none",
            duration: 1e3
          });},
        complete: function (e) { }
      });
      console.log(pdata);
    },
    bindBankpay: function (e) {
      this.bandAlipay(e);
    },
    bindChange: function(e) {
        let val = e.detail.value[0];
      
        this.setData({
          bankValue: this.data.bank[val],
        })

    },
    ClosePricker: function() {
        this.setData({
            isShowPricker: false,
        })
    },
    ConfirmPricker: function() {
        this.setData({
            isShowPricker: false,
        });
    },
    onReachBottom: function () {
      console.log("上拉加载", this.data.pagenum);
      this.data.mygd || !this.data.jzgd || this.data.isjzz || (this.setData({
        jzgd: !1
      }), this.getList());
    },
})